package testJdk.commonUse.dateAndCalendar.TestDate;

import cn.hutool.core.date.DateUtil;
import org.junit.Test;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Name : learn_jdk.date.TestDate.DateTest
 * @Description : 描述
 * Created by cyd on 2021-04-30 14:23:32
 */
public class DateTest {

    /**
     * date的构造
     * date的起始时间
     */
    @Test
    public void test02() {
        System.out.println(new Date(0));
        System.out.println(new Date(1000));
    }

    /**
     * date.getTime()
     * 返回的long值，是一个完整的时间
     * DateUtil构造一个标准的时间
     */
    @Test
    public void testGetTime() {
        Date date = new Date();
        long time = date.getTime();
        System.out.println(date);
        System.out.println(time);
        System.out.println(DateUtil.date(time));
        System.out.println(DateUtil.date(System.currentTimeMillis()));

    }

    /**
     * 获得时间的各个部分
     */
    @Test
    public void testGetPart() {
        Date date = new Date();

        System.out.println(date);

        //年份
        int year = date.getYear() + 1900;
        //月份
        int month = date.getMonth() + 1;
        //日期
        int day = date.getDate();
        //星期几
        int dayOfWeek = date.getDay();
        //小时
        int hour = date.getHours();
        //分钟
        int minute = date.getMinutes();
        //秒
        int second = date.getSeconds();

        System.out.println("年份：" + year);
        System.out.println("月份：" + month);
        System.out.println("日期：" + day);
        System.out.println("小时：" + hour);
        System.out.println("分钟：" + minute);
        System.out.println("秒：" + second);
        System.out.println("星期：" + dayOfWeek);
    }

    /**
     * 处理时间格式
     */
    @Test
    public void test03() {
        DateFormat df = new SimpleDateFormat(ExchangeConstants.FORMAT);
        String dateStr = df.format(new Date());
        System.out.println(dateStr);
    }
}
